home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ldb.zip / CBDRDEM1.CPP < prev    next >
C/C++ Source or Header  |  1991-10-18  |  2KB  |  92 lines

  1.     // cbdrdem1.cpp
  2.     // Demo CBinder for fixed size data.
  3.     // Link with binder.obj, sbinder.obj, cbinder.obj
  4.     
  5.     #include <fstream.h>
  6.     #include <iomanip.h>
  7.     #include "cbinder.hpp"
  8.  
  9.     #define ID_CBDR_INTCMP  1
  10.  
  11.     main()
  12.     {
  13.         CBinder B(sizeof(unsigned),5);
  14.  
  15.         CBinder::registerClass();
  16.  
  17.         for (unsigned i = 0;B.pushCLN(&i); i++);
  18.         
  19.         cout << "\n\nCBinder Stack of cloned "
  20.             "unsigned integers:\n\n";
  21.             
  22.         while (B++)
  23.             cout << "node: " << setw(6)
  24.                 << B.CurNode() 
  25.                 << "   contents:  " 
  26.                 << *(int *)(voiD)B << endl;
  27.             
  28.         B.setCurNode(3);
  29.         
  30.         B.link();
  31.         
  32.         cout << "\n\nCurNode: " << B.CurNode()
  33.             << "  contains:  " 
  34.             << *(int *)(voiD)B 
  35.             << endl << endl;
  36.         
  37.             
  38.         ofstream oS("cbdrdem1.txt");
  39.         if (oS)  {
  40.             oS << (StreamablE) B;
  41.             B.restream();
  42.             oS.close();
  43.             ifstream iS("cbdrdem1.txt");
  44.             if (iS)  {
  45.                 StreamablE C;
  46.                 iS >> C;
  47.                 iS.close();
  48.                 RestreamRegistry();
  49.                 if (C)
  50.                 { //***
  51.                 
  52.                 
  53.             cout << "\n\nStreamed and"
  54.                 << " reloaded CBinder "
  55.                 << "of cloned integers\n\n";
  56.             cout << "CurNode recorded in "
  57.                   << "stream and reloaded: " 
  58.                 << ((CBindeR)C)->CurNode()
  59.                 << "  contains:  " 
  60.                 << *(int *)(voiD)*(CBindeR)C 
  61.                 << endl << endl;
  62.             for (((CBindeR)C)->setCurNode();
  63.                 (*(CBindeR)C)++;
  64.                 cout << "node: " 
  65.                     << setw(6)
  66.                     << ((CBindeR)C)
  67.                         ->CurNode() 
  68.                     << "   contents:  " 
  69.                     << *(int *)(voiD)
  70.                         *(CBindeR)C 
  71.                         << endl);
  72.             delete (CBindeR) C;
  73.                   
  74.                   
  75.                 } //***
  76.                 else
  77.                   cout << "\n\nUnable to "
  78.                       << "reload"
  79.                     << " CBinder \n\n";
  80.             }
  81.             else
  82.                 cout << "\n\nUnable to "
  83.                   << "reopen"
  84.                   << " stream for input of"
  85.                   << " of CBinder \n\n";
  86.         }
  87.         
  88.         B.unlink();
  89.  
  90.         return 0;
  91.     }
  92.